﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

public partial class Ctl_ctlEmpCombo : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected ListItemCollection getEmplList()
    {
        if (cmbEmpl.Items.Count > 0)
                                return null;

        // проверить метку GlobalConstants.SiteMapItem_MangeTask  позвоено рулить чужими задачами?
        bool bUserInRole = iPageController.UserInRoleForSiteMapItem(GlobalConstants.SiteMapItem_MangeTask);// позвоено рулить чужими задачами?
        ListItemCollection coll = iPageController.GetEmplList(GlobalConstants.CurrentEmployeer.DepartmentId, false, bUserInRole);

        cmbEmpl.Items.Clear();
        foreach (ListItem i in coll)
        {            
            cmbEmpl.Items.Add(i);

        }

        return null;
    }



    [DefaultValue(false)]
    public bool AutoPostBack
    {
        get {return  cmbEmpl.AutoPostBack; }
        set { cmbEmpl.AutoPostBack = value; } 
    }

    
    public Unit Widtch
    {
        get { return cmbEmpl.Width; }
        set { cmbEmpl.Width=value; }
    }
    /// <summary>
    /// максмальное количество символов в строке комбобокесе по умолчанию 45
    /// </summary>

    
    

    

    public string CurrentValue
    {
        get { return cmbEmpl.SelectedItem.Value; }
        set 
        {
            if (cmbEmpl.Items.Count == 0)
                            getEmplList();

            for (int i = 0; i < cmbEmpl.Items.Count - 1; i++)
            {
                cmbEmpl.Items[i].Selected = cmbEmpl.Items[i].Value.Equals(value);
            }
        }
    }

    public string CurrentText
    {
        get { return cmbEmpl.SelectedItem.Text; }
    }

    
    public Func<ListItem, bool> OnSelectedIndexChanged;
    
    protected void cmbEmpl_SelectedIndexChanged(object sender, EventArgs e)
    {        
        if (null != OnSelectedIndexChanged)
            OnSelectedIndexChanged(cmbEmpl.SelectedItem);

    }
}
